package com.multids;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Order(value = -100)
@Aspect
public class DataSourceAspect {

    @Pointcut("execution(* com.multids.mapper.db1..*.*(..))")
    private void db1Aspect(){

    }

    @Pointcut("execution(* com.multids.mapper.db2..*.*(..))")
    private void db2Aspect(){}

    @Before("db1Aspect()")
    public void db1(){
        System.out.println("切换到db1");
        DataSourceHolder.setDBType(DBTypeEnum.db1);
    }

    @Before("db2Aspect()")
    public void db2(){
        System.out.println("切换到db2");
        DataSourceHolder.setDBType(DBTypeEnum.db2);
    }

}
